package com.yz.jdd.widget;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.youth.banner.loader.ImageLoader;
import com.yz.jdd.R;
import com.bumptech.glide.request.RequestOptions;

/**
 * Banner的图片加载器
 * xiongzhuang
 * 2019-05-16
 */
public class GlideImageLoader extends ImageLoader {
    @Override
    public void displayImage(Context context, Object path, ImageView imageView) {
        //Glide 加载图片简单用法
//        Glide.with(context).load(path).into(imageView);
        //图片缩放铺满
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        RequestOptions options = new RequestOptions()
                .priority(Priority.HIGH)
                .transform(new RoundedCorners(dip2px(context, 8)))
                .diskCacheStrategy(DiskCacheStrategy.ALL);
        Glide.with(context).load(path).apply(options).into(imageView);
    }

    public void displayImage(Context context, Object path, ImageView imageView, int dp) {
        //图片缩放铺满
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        RequestOptions options = new RequestOptions()
                .priority(Priority.HIGH)
                .transform(new RoundedCorners(dip2px(context, dp)))
                .diskCacheStrategy(DiskCacheStrategy.ALL);
        Glide.with(context).load(path).apply(options).into(imageView);
    }

    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }
}
